﻿<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:Custom="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:GameLogic_Logic="clr-namespace:GameLogic.Logic;assembly=GameLogic"
    xmlns:im="clr-namespace:Microsoft.Expression.Interactivity.Media;assembly=Microsoft.Expression.Interactions"
    xmlns:il="clr-namespace:Microsoft.Expression.Interactivity.Layout;assembly=Microsoft.Expression.Interactions"
    xmlns:local="clr-namespace:Bounce.Phone"
    mc:Ignorable="d"
    x:Class="Bounce.Phone.BounceGame"
    d:DesignWidth="480"
    d:DesignHeight="800" Height="Auto">

    <Canvas
        x:Name="LayoutRoot" Height="800">
        <Custom:Interaction.Behaviors>
            <GameLogic_Logic:GameLoop />
        </Custom:Interaction.Behaviors>
        <Canvas.Background>
            <LinearGradientBrush
                EndPoint="0.5,1"
                StartPoint="0.5,0">
                <GradientStop
                    Color="#FFB6E22A"
                    Offset="0" />
                <GradientStop
                    Color="#FF4B0C0C"
                    Offset="1" />
            </LinearGradientBrush>
        </Canvas.Background>
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup
                x:Name="GameStates">
                <VisualState
                    x:Name="GameReady">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames
                            Storyboard.TargetProperty="(UIElement.Visibility)"
                            Storyboard.TargetName="_gameReady">
                            <DiscreteObjectKeyFrame
                                KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Visible</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames
                            Storyboard.TargetProperty="(UIElement.Visibility)"
                            Storyboard.TargetName="_lifeLost">
                            <DiscreteObjectKeyFrame
                                KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState
                    x:Name="LifeLost">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames
                            Storyboard.TargetProperty="(UIElement.Visibility)"
                            Storyboard.TargetName="_gameReady">
                            <DiscreteObjectKeyFrame
                                KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames
                            Storyboard.TargetProperty="(UIElement.Visibility)"
                            Storyboard.TargetName="_lifeLost">
                            <DiscreteObjectKeyFrame
                                KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Visible</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState
                    x:Name="GameRunning">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames
                            Storyboard.TargetProperty="(UIElement.Visibility)"
                            Storyboard.TargetName="_lifeLost">
                            <DiscreteObjectKeyFrame
                                KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames
                            Storyboard.TargetProperty="(UIElement.Visibility)"
                            Storyboard.TargetName="_gameReady">
                            <DiscreteObjectKeyFrame
                                KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
        <Rectangle
            x:Name="_left"
            Width="10"
            Height="800">
            <Custom:Interaction.Behaviors>
                <GameLogic_Logic:StaticCollidableBehavior />
            </Custom:Interaction.Behaviors>
        </Rectangle>
        <Rectangle
            x:Name="_right"
            Width="10"
            Height="800"
            Canvas.Left="470">
            <Custom:Interaction.Behaviors>
                <GameLogic_Logic:StaticCollidableBehavior />
            </Custom:Interaction.Behaviors>
        </Rectangle>
        <Rectangle
            x:Name="_top"
            Height="10"
            Width="480">
            <Custom:Interaction.Behaviors>
                <GameLogic_Logic:StaticCollidableBehavior />
            </Custom:Interaction.Behaviors>
        </Rectangle>
        <Rectangle
            x:Name="_bottom"
            Height="20"
            Canvas.Top="780"
            Width="480">
            <Custom:Interaction.Triggers>
                <GameLogic_Logic:CollisionTrigger
                    SourceName="_bottom">
                    <im:PlaySoundAction
                        Source="/lostLife.mp3"
                        Volume="1" />
                </GameLogic_Logic:CollisionTrigger>
            </Custom:Interaction.Triggers>
            <Custom:Interaction.Behaviors>
                <GameLogic_Logic:StaticCollidableBehavior />
            </Custom:Interaction.Behaviors>
        </Rectangle>
        <Ellipse
            x:Name="_ball"
            Height="30"
            VerticalAlignment="Center"
            Fill="White"
            HorizontalAlignment="Center"
            Width="30"
            Canvas.Left="225"
            Canvas.Top="385">
            <Custom:Interaction.Triggers>
                <GameLogic_Logic:CollisionTrigger
                    SourceName="_bottom">
                    <GameLogic_Logic:ChangeGamePropertiesAction
                        ChangeLivesOnAction="True"
                        LivesIncrementValue="-1" />
                </GameLogic_Logic:CollisionTrigger>
                <GameLogic_Logic:CollisionTrigger
                    SourceName="_top">
                    <GameLogic_Logic:ChangeGamePropertiesAction
                        ChangeScoresOnAction="True"
                        ScoresIncrementValue="1" />
                </GameLogic_Logic:CollisionTrigger>
            </Custom:Interaction.Triggers>
            <Custom:Interaction.Behaviors>
                <GameLogic_Logic:MovingCollidableBehavior
                    CollisionEnabled="True"
                    CollisionType="Bounce"
                    AutoStart="True"
                    Speed="8"
                    Direction="90" />
            </Custom:Interaction.Behaviors>
        </Ellipse>
        <Grid x:Name="_paddleRange" Height="20" Canvas.Top="700" Width="480">
        	<Rectangle
        		x:Name="_paddle"
        		Fill="White"
        		RadiusX="6"
        		RadiusY="6" Width="100" Height="20">
        		<Custom:Interaction.Triggers>
        			<GameLogic_Logic:CollisionTrigger>
        				<im:PlaySoundAction
        					Source="/paddle.mp3"
        					Volume="1" />
        			</GameLogic_Logic:CollisionTrigger>
        		</Custom:Interaction.Triggers>
        		<Custom:Interaction.Behaviors>
        			<GameLogic_Logic:StaticCollidableBehavior />
        			<il:MouseDragElementBehavior ConstrainToParentBounds="True"/>
        		</Custom:Interaction.Behaviors>
        	</Rectangle>
        </Grid>
        <Grid
            x:Name="_gameReady"
            Background="#7F000000"
            Canvas.ZIndex="1"
            Height="800"
            Width="480" d:IsHidden="True">
            <Border
                HorizontalAlignment="Center"
                VerticalAlignment="Center"
                Background="#7F000000"
                BorderBrush="Black"
                BorderThickness="4"
                CornerRadius="10"
                Margin="10"
                Padding="10">
                <StackPanel>
                    <TextBlock
                        TextWrapping="Wrap"
                        Text="Try to get past the red paddle!"
                        HorizontalAlignment="Center"
                        FontSize="32"
                        TextAlignment="Center" Foreground="White" />
                    <Button
                        x:Name="_startGameBtn"
                        Content="Start Game" Click="_startGameBtn_Click">
                        <Custom:Interaction.Triggers>
                            <Custom:EventTrigger
                                EventName="Click">
                                <im:PlaySoundAction
                                    Source="/start.mp3"
                                    Volume="1" />
                            </Custom:EventTrigger>
                        </Custom:Interaction.Triggers>
                    </Button>
                </StackPanel>
            </Border>
        </Grid>
        <Grid
            x:Name="_lifeLost"
            Background="#7F000000"
            Canvas.ZIndex="1"
            Height="800"
            Width="480" d:IsHidden="True">
            <Border
                HorizontalAlignment="Center"
                VerticalAlignment="Center"
                Background="#7F000000"
                BorderBrush="Black"
                BorderThickness="4"
                CornerRadius="10"
                Margin="10"
                Padding="10">
                <StackPanel>
                    <TextBlock
                        TextWrapping="Wrap"
                        Text="Don't drop the ball!"
                        HorizontalAlignment="Center"
                        FontSize="32"
                        TextAlignment="Center" Foreground="White" />
                    <Button
                        x:Name="_continueGameBtn"
                        Content="Continue" Click="_continueGameBtn_Click">
                        <Custom:Interaction.Triggers>
                            <Custom:EventTrigger
                                EventName="Click">
                                <im:PlaySoundAction
                                    Source="/start.mp3"
                                    Volume="1" />
                            </Custom:EventTrigger>
                        </Custom:Interaction.Triggers>
                    </Button>
                </StackPanel>
            </Border>
        </Grid>
        <Rectangle
            x:Name="_enemy"
            Fill="#FF4C0D0C"
            Height="20"
            Width="100"
            HorizontalAlignment="Center"
            RadiusX="6"
            RadiusY="6"
            Stroke="White"
            Canvas.Left="190"
            Canvas.Top="70">
            <Custom:Interaction.Triggers>
                <GameLogic_Logic:CollisionTrigger>
                    <im:PlaySoundAction
                        Source="/wall.mp3"
                        Volume="1" />
                </GameLogic_Logic:CollisionTrigger>
            </Custom:Interaction.Triggers>
            <Custom:Interaction.Behaviors>
                <GameLogic_Logic:StaticCollidableBehavior />
                <GameLogic_Logic:FollowObjectBehavior
                    FollowObject="_ball" FollowPosition="X" />
            </Custom:Interaction.Behaviors>
        </Rectangle>
    </Canvas>
</UserControl>